//////////////////////////////////////////ok
#include"stdafx.h"
#include "bochs.h"



void IA32_CPU::XOR_EdGd(Ia32_Instruction_c *i)
{
  Bit32u op2_32, op1_32, result_32;

  op2_32 = IA32_READ_32BIT_REG(i->nnn());
  if (i->modC0()) 
  {
    op1_32 = IA32_READ_32BIT_REG(i->rm());
    result_32 = op1_32 ^ op2_32;
    IA32_WRITE_32BIT_REGZ(i->rm(), result_32);
  }
  else 
  {
    read_RMW_virtual_dword(i->seg(), IA32_RMAddr(i), &op1_32);
    result_32 = op1_32 ^ op2_32;
    write_RMW_virtual_dword(result_32);
  }

  IA32_SET_FLAGS_OSZAPC_RESULT_32(result_32, IA32_INSTR_LOGIC32);
}

void IA32_CPU::XOR_GdEd(Ia32_Instruction_c *i)
{
  Bit32u op1_32, op2_32, result_32;
  unsigned nnn = i->nnn();

  op1_32 = IA32_READ_32BIT_REG(nnn);

  if (i->modC0()) 
  {
    op2_32 = IA32_READ_32BIT_REG(i->rm());
  }
  else 
  {
    read_virtual_dword(i->seg(), IA32_RMAddr(i), &op2_32);
  }

  result_32 = op1_32 ^ op2_32;
  IA32_WRITE_32BIT_REGZ(nnn, result_32);
  IA32_SET_FLAGS_OSZAPC_RESULT_32(result_32, IA32_INSTR_LOGIC32);
}

void IA32_CPU::XOR_EAXId(Ia32_Instruction_c *i)
{
  Bit32u op1_32, op2_32, sum_32;

  op1_32 = EAX;
  op2_32 = i->Id();
  sum_32 = op1_32 ^ op2_32;
  EAX = sum_32;
  IA32_SET_FLAGS_OSZAPC_RESULT_32(sum_32, IA32_INSTR_LOGIC32);
}

void IA32_CPU::XOR_EdId(Ia32_Instruction_c *i)
{
  Bit32u op2_32, op1_32, result_32;

  op2_32 = i->Id();

  if (i->modC0()) 
  {
    op1_32 = IA32_READ_32BIT_REG(i->rm());
    result_32 = op1_32 ^ op2_32;
    IA32_WRITE_32BIT_REGZ(i->rm(), result_32);
  }
  else 
  {
    read_RMW_virtual_dword(i->seg(), IA32_RMAddr(i), &op1_32);
    result_32 = op1_32 ^ op2_32;
    write_RMW_virtual_dword(result_32);
  }

  IA32_SET_FLAGS_OSZAPC_RESULT_32(result_32, IA32_INSTR_LOGIC32);
}

void IA32_CPU::OR_EdId(Ia32_Instruction_c *i)
{
  Bit32u op2_32, op1_32, result_32;

  op2_32 = i->Id();

  if (i->modC0()) 
  {
    op1_32 = IA32_READ_32BIT_REG(i->rm());
    result_32 = op1_32 | op2_32;
    IA32_WRITE_32BIT_REGZ(i->rm(), result_32);
  }
  else 
  {
    read_RMW_virtual_dword(i->seg(), IA32_RMAddr(i), &op1_32);
    result_32 = op1_32 | op2_32;
    write_RMW_virtual_dword(result_32);
  }

  IA32_SET_FLAGS_OSZAPC_RESULT_32(result_32, IA32_INSTR_LOGIC32);
}

void IA32_CPU::NOT_Ed(Ia32_Instruction_c *i)
{
  Bit32u op1_32, result_32;

  if (i->modC0()) 
  {
    op1_32 = IA32_READ_32BIT_REG(i->rm());
    result_32 = ~op1_32;
    IA32_WRITE_32BIT_REGZ(i->rm(), result_32);
  }
  else 
  {
    read_RMW_virtual_dword(i->seg(), IA32_RMAddr(i), &op1_32);
    result_32 = ~op1_32;
    write_RMW_virtual_dword(result_32);
  }
}

void IA32_CPU::OR_EdGd(Ia32_Instruction_c *i)
{
  Bit32u op2_32, op1_32, result_32;

  op2_32 = IA32_READ_32BIT_REG(i->nnn());

  if (i->modC0()) 
  {
    op1_32 = IA32_READ_32BIT_REG(i->rm());
    result_32 = op1_32 | op2_32;
    IA32_WRITE_32BIT_REGZ(i->rm(), result_32);
  }
  else 
  {
    read_RMW_virtual_dword(i->seg(), IA32_RMAddr(i), &op1_32);
    result_32 = op1_32 | op2_32;
    write_RMW_virtual_dword(result_32);
  }

  IA32_SET_FLAGS_OSZAPC_RESULT_32(result_32, IA32_INSTR_LOGIC32);
}

void IA32_CPU::OR_GdEd(Ia32_Instruction_c *i)
{
  Bit32u op1_32, op2_32, result_32;

  op1_32 = IA32_READ_32BIT_REG(i->nnn());

  if (i->modC0()) 
  {
    op2_32 = IA32_READ_32BIT_REG(i->rm());
  }
  else 
  {
    read_virtual_dword(i->seg(), IA32_RMAddr(i), &op2_32);
  }

#if defined(IA32_HostAsm_Or32)
  Bit32u flags32;
  asmOr32(result_32, op1_32, op2_32, flags32);
  IA32_setEFlagsOSZAPC(flags32);
#else
  result_32 = op1_32 | op2_32;
  IA32_SET_FLAGS_OSZAPC_RESULT_32(result_32, IA32_INSTR_LOGIC32);
#endif

  IA32_WRITE_32BIT_REGZ(i->nnn(), result_32);
}

void IA32_CPU::OR_EAXId(Ia32_Instruction_c *i)
{
  Bit32u op1_32, op2_32, sum_32;

  op1_32 = EAX;
  op2_32 = i->Id();
  sum_32 = op1_32 | op2_32;
  EAX = sum_32;
  IA32_SET_FLAGS_OSZAPC_RESULT_32(sum_32, IA32_INSTR_LOGIC32);
}

void IA32_CPU::AND_EdGd(Ia32_Instruction_c *i)
{
  Bit32u op2_32, op1_32, result_32;

  op2_32 = IA32_READ_32BIT_REG(i->nnn());
  if (i->modC0()) 
  {
    op1_32 = IA32_READ_32BIT_REG(i->rm());
#if defined(IA32_HostAsm_And32)
    Bit32u flags32;
    asmAnd32(result_32, op1_32, op2_32, flags32);
    IA32_setEFlagsOSZAPC(flags32);
#else
    result_32 = op1_32 & op2_32;
#endif
    IA32_WRITE_32BIT_REGZ(i->rm(), result_32);
  }
  else 
  {
    read_RMW_virtual_dword(i->seg(), IA32_RMAddr(i), &op1_32);
#if defined(IA32_HostAsm_And32)
    Bit32u flags32;
    asmAnd32(result_32, op1_32, op2_32, flags32);
    IA32_setEFlagsOSZAPC(flags32);
#else
    result_32 = op1_32 & op2_32;
#endif
    write_RMW_virtual_dword(result_32);
  }

#if !defined(IA32_HostAsm_And32)
  IA32_SET_FLAGS_OSZAPC_RESULT_32(result_32, IA32_INSTR_LOGIC32);
#endif
}

void IA32_CPU::AND_GdEd(Ia32_Instruction_c *i)
{
  Bit32u op1_32, op2_32, result_32;

  op1_32 = IA32_READ_32BIT_REG(i->nnn());
  if (i->modC0()) 
  {
    op2_32 = IA32_READ_32BIT_REG(i->rm());
  }
  else 
  {
    read_virtual_dword(i->seg(), IA32_RMAddr(i), &op2_32);
  }
#if defined(IA32_HostAsm_And32)
  Bit32u flags32;
  asmAnd32(result_32, op1_32, op2_32, flags32);
  IA32_setEFlagsOSZAPC(flags32);
#else
  result_32 = op1_32 & op2_32;
  IA32_SET_FLAGS_OSZAPC_RESULT_32(result_32, IA32_INSTR_LOGIC32);
#endif

  IA32_WRITE_32BIT_REGZ(i->nnn(), result_32);
}

void IA32_CPU::AND_EAXId(Ia32_Instruction_c *i)
{
  Bit32u op1_32, op2_32, result_32;

  op1_32 = EAX;
  op2_32 = i->Id();

#if defined(IA32_HostAsm_And32)
  Bit32u flags32;
  asmAnd32(result_32, op1_32, op2_32, flags32);
  IA32_setEFlagsOSZAPC(flags32);
#else
  result_32 = op1_32 & op2_32;
  IA32_SET_FLAGS_OSZAPC_RESULT_32(result_32, IA32_INSTR_LOGIC32);
#endif

  EAX = result_32;
}

void IA32_CPU::AND_EdId(Ia32_Instruction_c *i)
{
  Bit32u op2_32, op1_32, result_32;

  op2_32 = i->Id();
  if (i->modC0()) 
  {
    op1_32 = IA32_READ_32BIT_REG(i->rm());
#if defined(IA32_HostAsm_And32)
    Bit32u flags32;
    asmAnd32(result_32, op1_32, op2_32, flags32);
    IA32_setEFlagsOSZAPC(flags32);
#else
    result_32 = op1_32 & op2_32;
#endif
    IA32_WRITE_32BIT_REGZ(i->rm(), result_32);
  }
  else 
  {
    read_RMW_virtual_dword(i->seg(), IA32_RMAddr(i), &op1_32);
#if defined(IA32_HostAsm_And32)
    Bit32u flags32;
    asmAnd32(result_32, op1_32, op2_32, flags32);
    IA32_setEFlagsOSZAPC(flags32);
#else
    result_32 = op1_32 & op2_32;
#endif
    write_RMW_virtual_dword(result_32);
  }

#if !defined(IA32_HostAsm_And32)
  IA32_SET_FLAGS_OSZAPC_RESULT_32(result_32, IA32_INSTR_LOGIC32);
#endif
}

void IA32_CPU::TEST_EdGd(Ia32_Instruction_c *i)
{
  Bit32u op2_32, op1_32;

  op2_32 = IA32_READ_32BIT_REG(i->nnn());
  if (i->modC0()) 
  {
    op1_32 = IA32_READ_32BIT_REG(i->rm());
  }
  else 
  {
    read_virtual_dword(i->seg(), IA32_RMAddr(i), &op1_32);
  }

#if defined(IA32_HostAsm_Test32)
  Bit32u flags32;
  asmTest32(op1_32, op2_32, flags32);
  IA32_setEFlagsOSZAPC(flags32);
#else
  Bit32u result_32 = op1_32 & op2_32;
  IA32_SET_FLAGS_OSZAPC_RESULT_32(result_32, IA32_INSTR_LOGIC32);
#endif
}

void IA32_CPU::TEST_EAXId(Ia32_Instruction_c *i)
{
  Bit32u op2_32, op1_32;

  op1_32 = EAX;
  op2_32 = i->Id();

#if defined(IA32_HostAsm_Test32)
  Bit32u flags32;
  asmTest32(op1_32, op2_32, flags32);
  IA32_setEFlagsOSZAPC(flags32);
#else
  Bit32u result_32 = op1_32 & op2_32;
  IA32_SET_FLAGS_OSZAPC_RESULT_32(result_32, IA32_INSTR_LOGIC32);
#endif
}

void IA32_CPU::TEST_EdId(Ia32_Instruction_c *i)
{
  Bit32u op2_32, op1_32;

  op2_32 = i->Id();

  if (i->modC0()) 
  {
    op1_32 = IA32_READ_32BIT_REG(i->rm());
  }
  else 
  {
    read_virtual_dword(i->seg(), IA32_RMAddr(i), &op1_32);
  }

#if defined(IA32_HostAsm_Test32)
  Bit32u flags32;
  asmTest32(op1_32, op2_32, flags32);
  IA32_setEFlagsOSZAPC(flags32);
#else
  Bit32u result_32 = op1_32 & op2_32;
  IA32_SET_FLAGS_OSZAPC_RESULT_32(result_32, IA32_INSTR_LOGIC32);
#endif
}
